package com.copsoftware.mantenimientos.tipocalle.service;

import java.util.Iterator;
import java.util.List;
import java.util.Set;

import org.hibernate.Hibernate;
import org.hibernate.Session;
import org.hibernate.Transaction;

import com.copsoftware.entity.GeoCalleImpl;
import com.copsoftware.entity.GeoTipoCalleImpl;
import com.copsoftware.hibernate.cfg.HibernateUtils;
import com.copsoftware.hibernate.pojo.GeoCalle;
import com.copsoftware.mantenimientos.tipocalle.dao.TipoCalleDAO;

public class TipoCalleService {

	public List getListaTipoCalle() throws Exception {
		Session session = HibernateUtils.getSessionFactory()
				.getCurrentSession();
		Transaction tx = null;
		List listaTipoCalle = null;
		try {
			tx = session.beginTransaction();
			TipoCalleDAO tipoCalleDAO = new TipoCalleDAO();
			tipoCalleDAO.setSession(session);
			listaTipoCalle = tipoCalleDAO.getListaTipoCalle();
			for (Iterator iter = listaTipoCalle.iterator(); iter.hasNext();) {
				GeoTipoCalleImpl element = (GeoTipoCalleImpl) iter.next();
				Set<GeoCalle> listaCalles = element.getGeoCalles();
				if (listaCalles != null) {					
						for (Iterator iterator = listaCalles.iterator(); iterator
								.hasNext();) {
							GeoCalleImpl element1 = (GeoCalleImpl) iterator
									.next();
							Hibernate.initialize(element1);
						}									
				}
			}
			tx.commit();
		} catch (Exception e) {
			tx.rollback();
			throw e;
		}
		return listaTipoCalle;
	}

	public static void main(String[] args) {
		TipoCalleService tipoCalleService = new TipoCalleService();
		try {
			List lista = tipoCalleService.getListaTipoCalle();
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
}
